package com.note.simpleshop.module.goods.service;
import com.note.simpleshop.entity.TbSpecOption;
import com.note.simpleshop.module.goods.dao.SpecOptionRepository;
import com.note.simpleshop.module.goods.vo.SpecOptionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SpecOptionService {
    private static final String CACHE_NAME="spec_option_cache";
    @Autowired
    private SpecOptionRepository specOptionRepository;

    @Cacheable(CACHE_NAME)
    public List<SpecOptionVo> findByGoodsIdAndSpecId(String goodsId, String specId)
    {
        List<SpecOptionVo> listVo=new ArrayList<SpecOptionVo>();
        List<TbSpecOption> list= specOptionRepository.findByGoodsIdAndSpecId(goodsId,specId);
        for(TbSpecOption specOption:list)
        {
            SpecOptionVo vo=SpecOptionVo.copy(specOption);
            listVo.add(vo);
        }
        return listVo;
    }
}
